package com.whj.apidriver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whj.apidriver.remote.ServiceOrderClient;
import com.whj.apidriver.remote.ServiceSsmPushClient;
import com.whj.apidriver.service.PayService;
import com.whj.internalcommon.constant.IdentityConstant;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.request.OrderRequest;
import com.whj.internalcommon.request.PushRequest;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: wanghaijun
 * @Date: 2023/2/28 - 02 - 28 - 16:27 
 * @Description: com.whj.apidriver.service.impl
 */


@Service
public class PayServiceImpl implements PayService {

    @Autowired
    private ServiceSsmPushClient serviceSsmPushClient;

    @Autowired
    private ServiceOrderClient serviceOrderClient;

    /**
     * 司机发起收款
     *
     * @param orderId 订单id
     * @param price 订单价格
     * @param passengerId 乘客id
     * @return
     */
    @Override
    public ResponseResult pushPayInfo(Long orderId, String price,Long passengerId) {

        //组装消息
        JSONObject message = new JSONObject();
        message.put("price",price);
        message.put("orderId",orderId);

        //推送消息
        PushRequest pushRequest = new PushRequest();
        pushRequest.setContent(message.toString());
        pushRequest.setIdentity(IdentityConstant.PASSENGER_IDENTITY);
        pushRequest.setUserId(passengerId);
        serviceSsmPushClient.push(pushRequest);
        //修改支付状态
        OrderRequest orderRequest = new OrderRequest();

        orderRequest.setOrderId(orderId);
        serviceOrderClient.pushPay(orderRequest);
        return ResponseResult.success("");
    }
}
